package com.ruoyi.standingbook.park.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.standingbook.park.domain.bo.ParkBo;
import com.ruoyi.standingbook.park.domain.vo.ParkPicVo;
import com.ruoyi.standingbook.park.domain.vo.ParkVo;
import com.ruoyi.standingbook.park.service.IParkService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 公园管养任务完成进度
 *
 * @author cc
 * @date 2023-08-29
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/standingbook/park")
public class ParkController extends BaseController {

    private final IParkService iParkService;

    /**
     * 查询公园管养任务完成进度列表
     */
    @SaCheckPermission("standingbook:park:list")
    @GetMapping("/list")
    public TableDataInfo<ParkVo> list(ParkBo bo, PageQuery pageQuery) {
        return iParkService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出公园管养任务完成进度列表
     */
    @SaCheckPermission("standingbook:park:export")
    @Log(title = "公园管养任务完成进度", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ParkBo bo, HttpServletResponse response) {
        List<ParkVo> list = iParkService.queryList(bo);
        ExcelUtil.exportExcel(list, "公园管养任务完成进度", ParkVo.class, response);
    }

    /**
     * 获取公园管养任务完成进度详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("standingbook:park:query")
    @GetMapping("/{id}")
    public R<ParkVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iParkService.queryById(id));
    }

    /**
     * 新增公园管养任务完成进度
     */
    @SaCheckPermission("standingbook:park:add")
    @Log(title = "公园管养任务完成进度", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ParkBo bo) {
        return toAjax(iParkService.insertByBo(bo));
    }

    /**
     * 修改公园管养任务完成进度
     */
    @SaCheckPermission("standingbook:park:edit")
    @Log(title = "公园管养任务完成进度", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ParkBo bo) {
        return toAjax(iParkService.updateByBo(bo));
    }

    /**
     * 删除公园管养任务完成进度
     *
     * @param ids 主键串
     */
    @SaCheckPermission("standingbook:park:remove")
    @Log(title = "公园管养任务完成进度", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iParkService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

    /**
     * 按指定日期查询智慧大屏公园管养台账
     * @param date 指定日期
     * @return
     */
    @SaIgnore()
    @GetMapping("/parkByDate")
    public R<List<ParkVo>> parkByDate(String date,String community) {
        return R.ok(iParkService.queryListByDate(date, community));
    }

    @SaIgnore()
    @GetMapping("/parkPic")
    public R<List<ParkPicVo>> parkPic(String date)  {
        return R.ok(iParkService.getParkPicByDate(date));
    }
}
